package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupAbnormalSummaryMapper;
import com.yunhai.device.service.OrrOutcupAbnormalSummaryService;
import com.yunhai.model.entity.orr.OrrOutcupAbnormalSummaryEntity;
import com.yunhai.model.vo.orr.OrrOutcupAbnormalSummaryQuery;
import com.yunhai.model.vo.orr.OrrOutcupAbnormalSummaryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupAbnormalSummaryServiceImpl implements OrrOutcupAbnormalSummaryService {

    @Resource
    private OrrOutcupAbnormalSummaryMapper orrOutcupAbnormalSummaryMapper;

    /**
     * 获取 OrrOutcupAbnormalSummary 分页列表
     */
    @Transactional
    public IPage getOrrOutcupAbnormalSummaryPagination(PaginationVo paginationVo, OrrOutcupAbnormalSummaryQuery orrOutcupAbnormalSummaryQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupAbnormalSummaryEntity> lqs = new LambdaQueryWrapper();
        orrOutcupAbnormalSummaryMapper.selectPage(page, lqs);

        List<OrrOutcupAbnormalSummaryEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupAbnormalSummary 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupAbnormalSummaryEntity> getOrrOutcupAbnormalSummaryAllList( OrrOutcupAbnormalSummaryQuery orrOutcupAbnormalSummaryQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupAbnormalSummaryEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupAbnormalSummaryEntity> list = orrOutcupAbnormalSummaryMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupAbnormalSummary 详情
     */
    @Transactional
    public OrrOutcupAbnormalSummaryEntity getOrrOutcupAbnormalSummaryDetail( Long id) throws Exception {

        OrrOutcupAbnormalSummaryEntity orrOutcupAbnormalSummaryEntity = orrOutcupAbnormalSummaryMapper.selectById(id);
        return orrOutcupAbnormalSummaryEntity;
    }


    /**
     * 新增 OrrOutcupAbnormalSummary
     * */
    @Transactional
    public void addOrrOutcupAbnormalSummary(OrrOutcupAbnormalSummaryVo orrOutcupAbnormalSummaryVo) throws Exception {

        OrrOutcupAbnormalSummaryEntity orrOutcupAbnormalSummaryEntity = new OrrOutcupAbnormalSummaryEntity();
        ReflectionCopy.copyProperties( orrOutcupAbnormalSummaryEntity, orrOutcupAbnormalSummaryVo );
        orrOutcupAbnormalSummaryMapper.insert(orrOutcupAbnormalSummaryEntity);
        return;
    }


    /**
     * 更新 OrrOutcupAbnormalSummary
     * */
    @Transactional
    public void updateOrrOutcupAbnormalSummary( OrrOutcupAbnormalSummaryVo orrOutcupAbnormalSummaryVo) throws Exception {

        if( orrOutcupAbnormalSummaryVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupAbnormalSummaryEntity orrOutcupAbnormalSummaryEntity = new OrrOutcupAbnormalSummaryEntity();
        ReflectionCopy.copyProperties( orrOutcupAbnormalSummaryEntity, orrOutcupAbnormalSummaryVo );
        orrOutcupAbnormalSummaryMapper.updateById(orrOutcupAbnormalSummaryEntity);
        return;
    }

    /**
     * 删除 OrrOutcupAbnormalSummary
     * */
    @Transactional
    public void batchRemoveOrrOutcupAbnormalSummary( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupAbnormalSummaryMapper.deleteBatchIds(ids);
    }

}